package com.hb.order.controller;

import com.hb.order.feign.StockFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    RestTemplate restTemplate;

    @Autowired
    StockFeignService stockFeignService;

    @RequestMapping("/add")
    public String add() {
        System.out.println("下单成功！");
        // 使用nacos 之後，这里 只需要说明域名，不需要指定端口
        String msg = restTemplate.getForObject("http://stock-service/stock/reduct", String.class);
        return "hello world " + msg;
    }

    @RequestMapping("/add-feign")
    public String addFeign() {
        System.out.println("下单成功！");
        // 使用nacos 之後，这里 只需要说明域名，不需要指定端口
        String msg = stockFeignService.reduct();
        return "hello feign " + msg;
    }
}
